package com.hspedu.set_;

/**
 * @Author Stringzhua
 * @Date 2024/3/11 21:07
 * description:
 */
@SuppressWarnings("all")
public class HashSetStructure {
    public static void main(String[] args) {
        //模拟一个HashSet的底层(HashMap的底层结构)
        //1.创建一个数组,数组的类型是Node[]
        //2.有些人直接把Node[] 数组称为 表[table]
        Node[] table = new Node[16];
        System.out.println("table = " + table);
        //3.创建结点,将john放在index为2的结点上
        Node john = new Node("john", null);
        table[2] = john;
        Node jack = new Node("jack", null);
        john.next = jack;//将jack 结点挂载到john
        Node rose = new Node("Rose", null);
        jack.next = rose;
        System.out.println("table = " + table);

        Node lucy = new Node("lucy", null);
        table[3]=lucy;//把lucy挂载到table表的索引为3的位置
        System.out.println("table = " + table);
    }
}

class Node {//结点,存储数据,可以指向下一个结点,从而形成链表
    Object item;//存放数据
    Node next;//指向下一个结点

    public Node(Object item, Node next) {
        this.item = item;
        this.next = next;
    }
}